import pymysql

# 建立链接
db = pymysql.connect(
    host='localhost',
    port=3306,
    database='jiangsu',
    user='root',
    password='root',
    charset='utf8'
)

# 创建游标
cursor = db.cursor()
sql = 'select * from student'
cursor.execute(sql)

data = cursor.fetchall()  # 获取所有查询结果

# 打印结果
columns = ['s_id', 's_name', 's_birth', 's_sex']
print(f'{"|".join(columns)}')
for row in data:
    print(f'|{row[0]}|{row[1]}|{row[2]}|{row[3]}')

# 关闭链接
cursor.close()
db.close()
